{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualizing\n",
    "EQTransformer comes with a few visualization tools to get a better sense of data that is beinig processed and the results. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1) continouty of the seismic data being processed:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Both prepocessor and mseed_predictor output a \"time_tracks.pkl\" file that contains the time info of data slices and their number of components. You can use this file to visualize the continuity and type of your data using the following module:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from EQTransformer.utils.plot import plot_data_chart\n",
    "plot_data_chart('time_tracks.pkl',  time_interval=10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2) continous waveforms:\n",
    "It is always a good idea to check the raw data: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "saved the plot as GS.CA06.00.HHZ__20190901T000000Z__20190902T000000Z.png\n"
     ]
    }
   ],
   "source": [
    "from EQTransformer.utils.plot import plot_detections, plot_helicorder\n",
    "plot_helicorder(input_mseed='downloads_mseeds/CA06/GS.CA06.00.HHZ__20190901T000000Z__20190902T000000Z.mseed', \n",
    "                input_csv=None, save_plot=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now you can mark those events that you have detected in your helicorder plot to check if you have catched most of them or you are missing too many of them (high false negativ). This togather with the events plots (in the Figure subfolders in your station_output folders) can give you a sense that if you are using a too high or too low threshold levels.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "saved the plot as GS.CA06.00.HH2__20190901T000000Z__20190902T000000Z.png\n"
     ]
    }
   ],
   "source": [
    "plot_helicorder(input_mseed='downloads_mseeds/CA06/GS.CA06.00.HH2__20190901T000000Z__20190902T000000Z.mseed', \n",
    "                input_csv='detections1/CA06_outputs/X_prediction_results.csv', save_plot=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3) map plot:\n",
    "You can also visulaize the number of detections over your network using this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot_detections(input_dir =\"detections1\",  input_json=\"station_list.json\", plot_type='station_map', marker_size=50)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4) histograms:\n",
    "And this command will automatically generate detection histograms for each station in your detection folder:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot_detections(input_dir =\"detections1\",  input_json=\"station_list.json\", plot_type='hist', time_window=120)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
